$(function(){
	
})


function save(){
	var flowData = $("#flowForm").serializeObject();

	var detailData = $('#detailForm').serializeObjectArray();

	var detail = {};
	detail['detailData'] = 'flownode';
	detail['row'] = detailData;
	
	flowData['table'] = detail
	

	if(!check(detail))
		return true;
	
	jQuery('body').showLoading();
	
	$.ajax({ 
		method: 'post',
		url: basePath() + 'flow/save.do',
		data: JSON.stringify(flowData),
		dataType: "json",
        contentType: "application/json",
		success: function(data){		

	    	if(data.result == 1){
				window.wxc.xcConfirm("保存成功！", window.wxc.xcConfirm.typeEnum.success,{
					onOk:function(v){
			    		parent.refreshData();		//刷新数据
					}
				});		
	    	} 
	    	else{
	    		window.wxc.xcConfirm(data.info, window.wxc.xcConfirm.typeEnum.error);
	    	}
	    	

	    	jQuery('body').hideLoading();
      	},
      	error : function(data){
	    	jQuery('body').hideLoading();
      	}
	});
}

function check(data){	
	var result = true;
	

	if($('#tableDetail').find('tbody').find('tr').not('.no-records-found').length == 0){
		window.wxc.xcConfirm('请增加<span style="color:red;"><strong>流程节点</strong></span>的行数据！', window.wxc.xcConfirm.typeEnum.info);
		return false;
	}
	
	
	var mustStr = "flownumber,flowname";
	
	var strMsg = "";
	var mustStrs = mustStr.split(',');
	for(var i=0; i<mustStrs.length; i++){
		var obj = $('[name="'+mustStrs[i]+'"]');
		if(obj.val() == ""){
			strMsg += obj.attr("placeholder") + "！<br />";
			
			result = false;
		}
	}
	

	
	
	if(strMsg != ""){
		window.wxc.xcConfirm(strMsg, window.wxc.xcConfirm.typeEnum.error);
	}
	
	return result;
}
